package com.ruoyi.system.util;

import com.ruoyi.system.domain.Stock;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class StockUtil {

    public static Stock transitionListToStock(List<String> stockList) {
        if (stockList == null || stockList.size() == 0) {
            return null;
        }
        Stock stockEntity = new Stock();
        try {
            String amount = stockList.get(10);
            if (!amount.equals("--")) {
                String num = amount.substring(0, amount.length() - 1);
                String util = amount.substring(amount.length() - 1);
                BigDecimal ratio = BigDecimal.ZERO;
                if (util.contains("万")) {
                    ratio = new BigDecimal(10000);
                } else if (util.contains("亿")) {
                    ratio = new BigDecimal(100000000);
                }
                BigDecimal bigDecimal = new BigDecimal(num);
                amount = bigDecimal.multiply(ratio).toString();
            }

            stockEntity = new Stock(stockList.get(0)
                    , stockList.get(1)
                    , stockList.get(2)
                    , stockList.get(3)
                    , stockList.get(5)
                    , stockList.get(4)
                    , null
                    , null
                    , null
                    , null
                    , null
                    , null
                    , amount);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return stockEntity;
        }
    }

    public static List<Stock> transitionListToStockList(List<List<String>> stockLists) {
        List<Stock> stocks = new ArrayList<>();
        for (List<String> stockList : stockLists) {
            Stock stockEntity = transitionListToStock(stockList);
            if (stockEntity != null) {
                stocks.add(stockEntity);
            }
        }
        return stocks;
    }
}
